package pzl.com.canvasapi.views;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.RectF;
import android.util.AttributeSet;
import android.view.View;

/**
 * @author zl.peng
 * @version [1.0, 2016-11-21]
 */
public class V_RoundRect extends View {
    int w;
    int h;
    Paint paint;

    public V_RoundRect(Context context) {
        super(context);
    }

    public V_RoundRect(Context context, AttributeSet attrs) {
        super(context, attrs);
        paint = new Paint();
        paint.setAntiAlias(true);
        paint.setStrokeWidth(5);
    }

    public V_RoundRect(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        w = getWidth();
        h = getHeight();
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);

        paint.setStyle(Paint.Style.STROKE);
        paint.setColor(Color.BLACK);
        RectF rectF = new RectF();
        rectF.top = 50;
        rectF.left = 50;
        rectF.right = w - 50;
        rectF.bottom = rectF.top + 400;
        canvas.drawRoundRect(rectF, 12, 12, paint);

        rectF.top = rectF.bottom + 15;
        rectF.bottom = rectF.top + 280;
        canvas.drawRoundRect(rectF, 12, 60, paint);
    }

}
